home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / gui / prcgntn1.lha / Precognition / source / BoolGadget.c < prev    next >
C/C++ Source or Header  |  1992-12-23  |  3KB  |  120 lines

  1. #include "BoolGadget.h"
  2. #include "BoolGadgetClass.h"
  3. #include "EmbossedGadgetClass.h"
  4. #include "pcgWindow.h"
  5. #include <proto/exec.h>
  6. #include "amigamem.h"
  7.  
  8. LONG BoolGadget_Value( BoolGadget *self )
  9. {
  10.    return (self->g.Flags & SELECTED);
  11. }
  12.  
  13.  
  14. LONG BoolGadget_SetValue( BoolGadget *self, LONG selection )
  15. {
  16.    struct pcgWindow *window;
  17.  
  18.    window = InteractorWindow( self );
  19.    if (window->Window) /* window is open */
  20.    {
  21.       /* NOTE: This may not be KOSHER.  The PROPER way is to remove
  22.        * the gadget from the window list, twiddle its bits, and
  23.        * then add it back to the list.  (It does work, though.)
  24.        */
  25.       Forbid();
  26.  
  27.       if (selection)
  28.          self->g.Flags |= SELECTED;
  29.       else
  30.          self->g.Flags &= (~SELECTED);
  31.  
  32.       Permit();
  33.    }
  34.    else /* Window is not open, can just do it the easy way */
  35.    {
  36.       if (selection)
  37.          self->g.Flags |= SELECTED;
  38.       else
  39.          self->g.Flags &= (~SELECTED);
  40.    }
  41.  
  42.    return selection;
  43. }
  44.  
  45. #ifdef BUILDER
  46. #include "BuilderMethods.h"
  47. #include "GraphicObject_Builder.h"
  48. #include "BoolGadget_coder.h"
  49.  
  50. BoolGadget *BoolGadget_New( BoolGadget *self )
  51. {
  52.    BoolGadget *new_self;
  53.  
  54.    if (new_self = (BoolGadget*) Amalloc( sizeof(BoolGadget) ) )
  55.    {
  56.       char *label = Title(self);
  57.  
  58.       BoolGadget_Init( new_self, self->Location.x, self->Location.y,
  59.          self->Size.x, self->Size.y, self->Pens, label );
  60.  
  61.       GiveItAName( new_self );
  62.    }
  63.  
  64.    return new_self;
  65. }
  66.  
  67. struct BuilderMethods BoolGadget_bm;
  68.  
  69. #endif
  70.  
  71. BOOL BoolGadget_elaborated = FALSE;
  72.  
  73. struct ValuatorClass BoolGadget_Class;
  74.  
  75. void BoolGadgetClass_Init( struct ValuatorClass *class )
  76. {
  77.    ValuatorClass_Init( class );
  78.    EmbossedGadgetClass_Init( class );
  79.    class->isa           = ValuatorClass();
  80.    class->ClassName     = "BoolGadget";
  81.    class->Value         = BoolGadget_Value;
  82.    class->SetValue      = BoolGadget_SetValue;
  83.  
  84. #ifdef BUILDER
  85.    class->BuilderMethods = &BoolGadget_bm;
  86.    go_InitBuilderMethods( &BoolGadget_bm );
  87.    BoolGadget_bm.New       = BoolGadget_New;
  88.    BoolGadget_bm.WriteCode = BoolGadget_WriteCode;
  89. #endif
  90. }
  91.  
  92.  
  93. struct ValuatorClass *BoolGadgetClass( void )
  94. {
  95.    if (! BoolGadget_elaborated)
  96.    {
  97.       BoolGadgetClass_Init( &BoolGadget_Class );
  98.       BoolGadget_elaborated = TRUE;
  99.    }
  100.  
  101.    return &BoolGadget_Class;
  102. }
  103.  
  104.  
  105.  
  106. void BoolGadget_Init( BoolGadget *self,
  107.                       PIXELS      LeftEdge,
  108.                       PIXELS      TopEdge,
  109.                       PIXELS      Width,
  110.                       PIXELS      Height,
  111.                       pcg_3DPens  Pens,
  112.                       char       *Label )
  113. {
  114.    EmbossedGadget_Init( self, LeftEdge, TopEdge, Width, Height,
  115.                         GADGHCOMP, RELVERIFY, BOOLGADGET,
  116.                         Pens, Label );
  117.  
  118.    self->isa = BoolGadgetClass();
  119. }
  120.